package com.hopes.bizz.packet.hj212.config;

import com.hopes.bizz.packet.hj212.handler.Hj212ChannelInboundHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lyb
 * @version 1.0
 * @date 2023/2/27 14:27
 */

@Component
public class BootNettyChannelInitializer extends ChannelInitializer<Channel> {

    @Autowired
    private Hj212ChannelInboundHandler hj212ChannelInboundHandler;

    @Override
    @SneakyThrows
    protected void initChannel(Channel ch) {
        ch.pipeline().addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));
        ch.pipeline().addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
        ch.pipeline().addLast(hj212ChannelInboundHandler);
    }

}
